<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang = "en">

<head>

<link rel="shortcut icon" href="http://algs4.cs.princeton.edu/favicon.ico">
<link rel="stylesheet"    href="http://algs4.cs.princeton.edu/java.css" type="text/css">

<title>SET.java</title>

<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<meta NAME="AUTHOR" CONTENT="Robert Sedgewick and Kevin Wayne">
<meta NAME="DESCRIPTION" CONTENT="SET code in Java">
<meta NAME="TITLE" CONTENT="SET code in Java">
<meta NAME="KEYWORDS" CONTENT="SET,java,programming,computer science,algorithm,data structure,program,code">
<meta NAME="ROBOTS" CONTENT="INDEX,FOLLOW">

</head>


<body>
<center><h1>SET.java</h1></center><p><br>

Below is the syntax highlighted version of <a href = "SET.java">SET.java</a>.
<p><br>

<!-- Generator: GNU source-highlight 3.1.6
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span class="comment">/******************************************************************************</span>
<span class="comment"> *  Compilation:  javac SET.java</span>
<span class="comment"> *  Execution:    java SET</span>
<span class="comment"> *  Dependencies: StdOut.java</span>
<span class="comment"> *  </span>
<span class="comment"> *  Set implementation using Java's TreeSet library.</span>
<span class="comment"> *  Does not allow duplicates.</span>
<span class="comment"> *</span>
<span class="comment"> *  % java SET</span>
<span class="comment"> *  128.112.136.11</span>
<span class="comment"> *  208.216.181.15</span>
<span class="comment"> *  null</span>
<span class="comment"> *</span>
<span class="comment"> ******************************************************************************/</span>

<span class="preproc">package</span><span class="normal"> edu</span><span class="symbol">.</span><span class="normal">princeton</span><span class="symbol">.</span><span class="normal">cs</span><span class="symbol">.</span><span class="normal">algs4</span><span class="symbol">;</span>

<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">Iterator</span><span class="symbol">;</span>
<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">NoSuchElementException</span><span class="symbol">;</span>
<span class="preproc">import</span><span class="normal"> java</span><span class="symbol">.</span><span class="normal">util</span><span class="symbol">.</span><span class="normal">TreeSet</span><span class="symbol">;</span>

<span class="comment">/**</span>
<span class="comment"> *  The </span><span class="keyword">&lt;tt&gt;</span><span class="comment">SET</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> class represents an ordered set of comparable keys.</span>
<span class="comment"> *  It supports the usual </span><span class="keyword">&lt;em&gt;</span><span class="comment">add</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">contains</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, and </span><span class="keyword">&lt;em&gt;</span><span class="comment">delete</span><span class="keyword">&lt;/em&gt;</span>
<span class="comment"> *  methods. It also provides ordered methods for finding the </span><span class="keyword">&lt;em&gt;</span><span class="comment">minimum</span><span class="keyword">&lt;/em&gt;</span><span class="comment">,</span>
<span class="comment"> *  </span><span class="keyword">&lt;em&gt;</span><span class="comment">maximum</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">floor</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, and </span><span class="keyword">&lt;em&gt;</span><span class="comment">ceiling</span><span class="keyword">&lt;/em&gt;</span><span class="comment"> and set methods</span>
<span class="comment"> *  for </span><span class="keyword">&lt;em&gt;</span><span class="comment">union</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">intersection</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, and </span><span class="keyword">&lt;em&gt;</span><span class="comment">equality</span><span class="keyword">&lt;/em&gt;</span><span class="comment">.</span>
<span class="comment"> *  </span><span class="keyword">&lt;p&gt;</span>
<span class="comment"> *  Even though this implementation include the method </span><span class="keyword">&lt;tt&gt;</span><span class="comment">equals()</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">, it</span>
<span class="comment"> *  does not support the method </span><span class="keyword">&lt;tt&gt;</span><span class="comment">hashCode()</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> because sets are mutable.</span>
<span class="comment"> *  </span><span class="keyword">&lt;p&gt;</span>
<span class="comment"> *  This implementation uses a balanced binary search tree. It requires that</span>
<span class="comment"> *  the key type implements the </span><span class="keyword">&lt;tt&gt;</span><span class="comment">Comparable</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> interface and calls the</span>
<span class="comment"> *  </span><span class="keyword">&lt;tt&gt;</span><span class="comment">compareTo()</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> and method to compare two keys. It does not call either</span>
<span class="comment"> *  </span><span class="keyword">&lt;tt&gt;</span><span class="comment">equals()</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> or </span><span class="keyword">&lt;tt&gt;</span><span class="comment">hashCode()</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">.</span>
<span class="comment"> *  The </span><span class="keyword">&lt;em&gt;</span><span class="comment">add</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">contains</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">delete</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">minimum</span><span class="keyword">&lt;/em&gt;</span><span class="comment">,</span>
<span class="comment"> *  </span><span class="keyword">&lt;em&gt;</span><span class="comment">maximum</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, </span><span class="keyword">&lt;em&gt;</span><span class="comment">ceiling</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, and </span><span class="keyword">&lt;em&gt;</span><span class="comment">floor</span><span class="keyword">&lt;/em&gt;</span><span class="comment"> methods take</span>
<span class="comment"> *  logarithmic time in the worst case.</span>
<span class="comment"> *  The </span><span class="keyword">&lt;em&gt;</span><span class="comment">size</span><span class="keyword">&lt;/em&gt;</span><span class="comment">, and </span><span class="keyword">&lt;em&gt;</span><span class="comment">is-empty</span><span class="keyword">&lt;/em&gt;</span><span class="comment"> operations take constant time.</span>
<span class="comment"> *  Construction takes constant time.</span>
<span class="comment"> *  </span><span class="keyword">&lt;p&gt;</span>
<span class="comment"> *  This implementation uses a balanced binary search tree. It requires that</span>
<span class="comment"> *  For additional documentation, see</span>
<span class="comment"> *  </span><span class="keyword">&lt;a</span><span class="normal"> </span><span class="type">href</span><span class="symbol">=</span><span class="string">"http://algs4.cs.princeton.edu/35applications"</span><span class="keyword">&gt;</span><span class="comment">Section 3.5</span><span class="keyword">&lt;/a&gt;</span><span class="comment"> of</span>
<span class="comment"> *  </span><span class="keyword">&lt;i&gt;</span><span class="comment">Algorithms in Java, 4th Edition</span><span class="keyword">&lt;/i&gt;</span><span class="comment"> by Robert Sedgewick and Kevin Wayne.</span>
<span class="comment"> *</span>
<span class="comment"> *  </span><span class="type">@author</span><span class="comment"> Robert Sedgewick</span>
<span class="comment"> *  </span><span class="type">@author</span><span class="comment"> Kevin Wayne</span>
<span class="comment"> *</span>
<span class="comment"> *  </span><span class="type">@param</span><span class="comment"> </span><span class="keyword">&lt;Key&gt;</span><span class="comment"> the generic type of a key in this set</span>
<span class="comment"> */</span>

<span class="keyword">public</span><span class="normal"> </span><span class="keyword">class</span><span class="normal"> </span><span class="classname">SET</span><span class="symbol">&lt;</span><span class="normal">Key </span><span class="usertype">extends</span><span class="normal"> Comparable</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;&gt;</span><span class="normal"> </span><span class="keyword">implements</span><span class="normal"> Iterable</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">    </span><span class="keyword">private</span><span class="normal"> </span><span class="usertype">TreeSet&lt;Key&gt;</span><span class="normal"> set</span><span class="symbol">;</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Initializes an empty set.</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="function">SET</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        set </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> TreeSet</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;();</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Initializes a new set that is an independent copy of the specified set.</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="function">SET</span><span class="symbol">(</span><span class="usertype">SET&lt;Key&gt;</span><span class="normal"> x</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        set </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> TreeSet</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;(</span><span class="normal">x</span><span class="symbol">.</span><span class="normal">set</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Adds the key to this set (if it is not already present).</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  key the key to add</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">add</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">key </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called add() with a null key"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="normal">key</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>


<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns true if this set contains the given key.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  key the key</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> </span><span class="keyword">&lt;tt&gt;</span><span class="comment">true</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> if this set contains </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">;</span>
<span class="comment">     *         </span><span class="keyword">&lt;tt&gt;</span><span class="comment">false</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> otherwise</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">contains</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">key </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called contains() with a null key"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">contains</span><span class="symbol">(</span><span class="normal">key</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Removes the specified key from this set (if the set contains the specified key).</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  key the key</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">delete</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">key </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called delete() with a null key"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">remove</span><span class="symbol">(</span><span class="normal">key</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the number of keys in this set.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the number of keys in this set</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">size</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">size</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns true if this set is empty.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> </span><span class="keyword">&lt;tt&gt;</span><span class="comment">true</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> if this set is empty;</span>
<span class="comment">     *         </span><span class="keyword">&lt;tt&gt;</span><span class="comment">false</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> otherwise</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">isEmpty</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> </span><span class="function">size</span><span class="symbol">()</span><span class="normal"> </span><span class="symbol">==</span><span class="normal"> </span><span class="number">0</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>
<span class="normal"> </span>
<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns all of the keys in this set, as an iterator.</span>
<span class="comment">     * To iterate over all of the keys in a set named </span><span class="keyword">&lt;tt&gt;</span><span class="comment">set</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">, use the</span>
<span class="comment">     * foreach notation: </span><span class="keyword">&lt;tt&gt;</span><span class="comment">for (Key key : set)</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> an iterator to all of the keys in this set</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Iterator&lt;Key&gt;</span><span class="normal"> </span><span class="function">iterator</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">iterator</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the largest key in this set.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the largest key in this set</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NoSuchElementException if this set is empty</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">max</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function">isEmpty</span><span class="symbol">())</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NoSuchElementException</span><span class="symbol">(</span><span class="string">"called max() with empty set"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">last</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the smallest key in this set.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the smallest key in this set</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NoSuchElementException if this set is empty</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">min</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="function">isEmpty</span><span class="symbol">())</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NoSuchElementException</span><span class="symbol">(</span><span class="string">"called min() with empty set"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">first</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span>


<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the smallest key in this set greater than or equal to </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  key the key</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the smallest key in this set greater than or equal to </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NoSuchElementException if there is no such key</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">ceiling</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">key </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called ceiling() with a null key"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="usertype">Key</span><span class="normal"> k </span><span class="symbol">=</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">ceiling</span><span class="symbol">(</span><span class="normal">key</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">k </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NoSuchElementException</span><span class="symbol">(</span><span class="string">"all keys are less than "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> key</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> k</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the largest key in this set less than or equal to </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  key the key</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the largest key in this set table less than or equal to </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">key</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NoSuchElementException if there is no such key</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">Key</span><span class="normal"> </span><span class="function">floor</span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">key </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called floor() with a null key"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="usertype">Key</span><span class="normal"> k </span><span class="symbol">=</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">floor</span><span class="symbol">(</span><span class="normal">key</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">k </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NoSuchElementException</span><span class="symbol">(</span><span class="string">"all keys are greater than "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> key</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> k</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the union of this set and that set.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  that the other set</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the union of this set and that set</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">that</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">SET&lt;Key&gt; union(SET&lt;Key&gt;</span><span class="normal"> that</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">that </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called union() with a null argument"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="usertype">SET&lt;Key&gt;</span><span class="normal"> c </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> SET</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;();</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> x </span><span class="symbol">:</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            c</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">);</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> x </span><span class="symbol">:</span><span class="normal"> that</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            c</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">);</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> c</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns the intersection of this set and that set.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  that the other set</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> the intersection of this set and that set</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> NullPointerException if </span><span class="keyword">&lt;tt&gt;</span><span class="comment">that</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> is </span><span class="keyword">&lt;tt&gt;</span><span class="comment">null</span><span class="keyword">&lt;/tt&gt;</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">SET&lt;Key&gt; intersects(SET&lt;Key&gt;</span><span class="normal"> that</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">that </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">NullPointerException</span><span class="symbol">(</span><span class="string">"called intersects() with a null argument"</span><span class="symbol">);</span>
<span class="normal">        </span><span class="usertype">SET&lt;Key&gt;</span><span class="normal"> c </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> SET</span><span class="symbol">&lt;</span><span class="normal">Key</span><span class="symbol">&gt;();</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="keyword">this</span><span class="symbol">.</span><span class="function">size</span><span class="symbol">()</span><span class="normal"> </span><span class="symbol">&lt;</span><span class="normal"> that</span><span class="symbol">.</span><span class="function">size</span><span class="symbol">())</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> x </span><span class="symbol">:</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">                </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">that</span><span class="symbol">.</span><span class="function">contains</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">))</span><span class="normal"> c</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">);</span>
<span class="normal">            </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="keyword">else</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> x </span><span class="symbol">:</span><span class="normal"> that</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">                </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="keyword">this</span><span class="symbol">.</span><span class="function">contains</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">))</span><span class="normal"> c</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="normal">x</span><span class="symbol">);</span>
<span class="normal">            </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="cbracket">}</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> c</span><span class="symbol">;</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**       </span>
<span class="comment">     * Compares this set to the specified set.</span>
<span class="comment">     * </span><span class="keyword">&lt;p&gt;</span>
<span class="comment">     * Note that this method declares two empty sets to be equal</span>
<span class="comment">     * even if they are parameterized by different generic types.</span>
<span class="comment">     * This is consistent with the behavior of </span><span class="keyword">&lt;tt&gt;</span><span class="comment">equals()</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> </span>
<span class="comment">     * within Java's Collections framework.</span>
<span class="comment">     *       </span>
<span class="comment">     * </span><span class="type">@param</span><span class="comment">  other the other set</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> </span><span class="keyword">&lt;tt&gt;</span><span class="comment">true</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> if this set equals </span><span class="keyword">&lt;tt&gt;</span><span class="comment">other</span><span class="keyword">&lt;/tt&gt;</span><span class="comment">;</span>
<span class="comment">     *         </span><span class="keyword">&lt;tt&gt;</span><span class="comment">false</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> otherwise</span>
<span class="comment">     */</span>
<span class="normal">    @Override</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">boolean</span><span class="normal"> </span><span class="function">equals</span><span class="symbol">(</span><span class="usertype">Object</span><span class="normal"> other</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">other </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">true</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">other </span><span class="symbol">==</span><span class="normal"> </span><span class="keyword">null</span><span class="symbol">)</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">if</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">other</span><span class="symbol">.</span><span class="function">getClass</span><span class="symbol">()</span><span class="normal"> </span><span class="symbol">!=</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">.</span><span class="function">getClass</span><span class="symbol">())</span><span class="normal"> </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">false</span><span class="symbol">;</span>
<span class="normal">        </span><span class="usertype">SET</span><span class="normal"> that </span><span class="symbol">=</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">SET</span><span class="symbol">)</span><span class="normal"> other</span><span class="symbol">;</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">.</span><span class="normal">set</span><span class="symbol">.</span><span class="function">equals</span><span class="symbol">(</span><span class="normal">that</span><span class="symbol">.</span><span class="normal">set</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * This operation is not supported because sets are mutable.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> does not return a value</span>
<span class="comment">     * </span><span class="type">@throws</span><span class="comment"> UnsupportedOperationException if called</span>
<span class="comment">     */</span>
<span class="normal">    @Override</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="type">int</span><span class="normal"> </span><span class="function">hashCode</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="keyword">throw</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">UnsupportedOperationException</span><span class="symbol">(</span><span class="string">"hashCode() is not supported because sets are mutable"</span><span class="symbol">);</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Returns a string representation of this set.</span>
<span class="comment">     *</span>
<span class="comment">     * </span><span class="type">@return</span><span class="comment"> a string representation of this set, with the keys separated</span>
<span class="comment">     *         by single spaces</span>
<span class="comment">     */</span>
<span class="normal">    @Override</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="usertype">String</span><span class="normal"> </span><span class="function">toString</span><span class="symbol">()</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="usertype">StringBuilder</span><span class="normal"> s </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> </span><span class="function">StringBuilder</span><span class="symbol">();</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">Key</span><span class="normal"> key </span><span class="symbol">:</span><span class="normal"> </span><span class="keyword">this</span><span class="symbol">)</span>
<span class="normal">            s</span><span class="symbol">.</span><span class="function">append</span><span class="symbol">(</span><span class="normal">key </span><span class="symbol">+</span><span class="normal"> </span><span class="string">" "</span><span class="symbol">);</span>
<span class="normal">        </span><span class="keyword">return</span><span class="normal"> s</span><span class="symbol">.</span><span class="function">toString</span><span class="symbol">();</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="normal">    </span><span class="comment">/**</span>
<span class="comment">     * Unit tests the </span><span class="keyword">&lt;tt&gt;</span><span class="comment">SET</span><span class="keyword">&lt;/tt&gt;</span><span class="comment"> data type.</span>
<span class="comment">     */</span>
<span class="normal">    </span><span class="keyword">public</span><span class="normal"> </span><span class="keyword">static</span><span class="normal"> </span><span class="type">void</span><span class="normal"> </span><span class="function">main</span><span class="symbol">(</span><span class="normal">String</span><span class="symbol">[]</span><span class="normal"> args</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">        </span><span class="usertype">SET&lt;String&gt;</span><span class="normal"> set </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> SET</span><span class="symbol">&lt;</span><span class="normal">String</span><span class="symbol">&gt;();</span>

<span class="normal">        </span><span class="comment">// insert some keys</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.cs.princeton.edu"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.cs.princeton.edu"</span><span class="symbol">);</span><span class="normal">    </span><span class="comment">// overwrite old value</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.princeton.edu"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.math.princeton.edu"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.yale.edu"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.amazon.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.simpsons.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.stanford.edu"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.google.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.ibm.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.apple.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.slashdot.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.whitehouse.gov"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.espn.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.snopes.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.movies.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.cnn.com"</span><span class="symbol">);</span>
<span class="normal">        set</span><span class="symbol">.</span><span class="function">add</span><span class="symbol">(</span><span class="string">"www.iitb.ac.in"</span><span class="symbol">);</span>


<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="normal">set</span><span class="symbol">.</span><span class="function">contains</span><span class="symbol">(</span><span class="string">"www.cs.princeton.edu"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(!</span><span class="normal">set</span><span class="symbol">.</span><span class="function">contains</span><span class="symbol">(</span><span class="string">"www.harvardsucks.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="normal">set</span><span class="symbol">.</span><span class="function">contains</span><span class="symbol">(</span><span class="string">"www.simpsons.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">();</span>

<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="string">"ceiling(www.simpsonr.com) = "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">ceiling</span><span class="symbol">(</span><span class="string">"www.simpsonr.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="string">"ceiling(www.simpsons.com) = "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">ceiling</span><span class="symbol">(</span><span class="string">"www.simpsons.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="string">"ceiling(www.simpsont.com) = "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">ceiling</span><span class="symbol">(</span><span class="string">"www.simpsont.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="string">"floor(www.simpsonr.com)   = "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">floor</span><span class="symbol">(</span><span class="string">"www.simpsonr.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="string">"floor(www.simpsons.com)   = "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">floor</span><span class="symbol">(</span><span class="string">"www.simpsons.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="string">"floor(www.simpsont.com)   = "</span><span class="normal"> </span><span class="symbol">+</span><span class="normal"> set</span><span class="symbol">.</span><span class="function">floor</span><span class="symbol">(</span><span class="string">"www.simpsont.com"</span><span class="symbol">));</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">();</span>


<span class="normal">        </span><span class="comment">// print out all keys in this set in lexicographic order</span>
<span class="normal">        </span><span class="keyword">for</span><span class="normal"> </span><span class="symbol">(</span><span class="usertype">String</span><span class="normal"> s </span><span class="symbol">:</span><span class="normal"> set</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal">            StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="normal">s</span><span class="symbol">);</span>
<span class="normal">        </span><span class="cbracket">}</span>

<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">();</span>
<span class="normal">        </span><span class="usertype">SET&lt;String&gt;</span><span class="normal"> set2 </span><span class="symbol">=</span><span class="normal"> </span><span class="keyword">new</span><span class="normal"> SET</span><span class="symbol">&lt;</span><span class="normal">String</span><span class="symbol">&gt;(</span><span class="normal">set</span><span class="symbol">);</span>
<span class="normal">        StdOut</span><span class="symbol">.</span><span class="function">println</span><span class="symbol">(</span><span class="normal">set</span><span class="symbol">.</span><span class="function">equals</span><span class="symbol">(</span><span class="normal">set2</span><span class="symbol">));</span>
<span class="normal">    </span><span class="cbracket">}</span>

<span class="cbracket">}</span>

<span class="comment">/******************************************************************************</span>
<span class="comment"> *  Copyright 2002-2015, Robert Sedgewick and Kevin Wayne.</span>
<span class="comment"> *</span>
<span class="comment"> *  This file is part of algs4.jar, which accompanies the textbook</span>
<span class="comment"> *</span>
<span class="comment"> *      Algorithms, 4th edition by Robert Sedgewick and Kevin Wayne,</span>
<span class="comment"> *      Addison-Wesley Professional, 2011, ISBN 0-321-57351-X.</span>
<span class="comment"> *      </span><span class="url">http://algs4.cs.princeton.edu</span>
<span class="comment"> *</span>
<span class="comment"> *</span>
<span class="comment"> *  algs4.jar is free software: you can redistribute it and/or modify</span>
<span class="comment"> *  it under the terms of the GNU General Public License as published by</span>
<span class="comment"> *  the Free Software Foundation, either version 3 of the License, or</span>
<span class="comment"> *  (at your option) any later version.</span>
<span class="comment"> *</span>
<span class="comment"> *  algs4.jar is distributed in the hope that it will be useful,</span>
<span class="comment"> *  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="comment"> *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="comment"> *  GNU General Public License for more details.</span>
<span class="comment"> *</span>
<span class="comment"> *  You should have received a copy of the GNU General Public License</span>
<span class="comment"> *  along with algs4.jar.  If not, see </span><span class="url">http://www.gnu.org/licenses.</span>
<span class="comment"> ******************************************************************************/</span>
</tt></pre>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-10811519-2");
pageTracker._trackPageview();
} catch(err) {}</script>

</body>

<p><br><address><small>
Last updated: Mon Mar 21 10:51:08 EDT 2016.
</small></address>

</html>
